import {createStore,combineReducers,applyMiddleware} from 'redux';
import thunk from 'redux-thunk'

const userReducer = ((state={userList:[1,2,3]},action) => {
    switch(action.type){
        case 'search':
            return {userList:action.content}
        case 'add':
            return {...state,userList:[action.content,...state.userList]}
        case 'delete':
            return {userList:action.content}
        case 'editor':
            return {userList:[action.content,...state.userList]}
        default:
            return state;
        }
    })

    const loginReducer = ((state={islogin:false,sta:{}},action) => {
        switch(action.type){
            case 'login':
                return {islogin:true,sta:action.value}
            case 'exit':
                return {islogin:false,sta:{}}
            default:
                return state;
        }
    })


const cityCulutureReducer = ((state={cityCulutureList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,cityCulutureList:[action.content,...state.cityCulutureList]}
        case 'add':
            return {...state,cityCulutureList:[action.content,...state.cityCulutureList]}
        case 'delete':
            return {...state,cityCulutureList:[action.content,...state.cityCulutureList]}
        case 'editor':
            return {...state,cityCulutureList:[action.content,...state.cityCulutureList]}
        default:
            return state;
        }
    })


const interestReducer = ((state={interestList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,interestList:[action.content,...state.interestList]}
        case 'add':
            return {...state,interestList:[action.content,...state.interestList]}
        case 'delete':
            return {...state,interestList:[action.content,...state.interestList]}
        case 'editor':
            return {...state,interestList:[action.content,...state.interestList]}
        default:
            return state;
        }
    })

const nearbyReducer = ((state={nearbyList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,nearbyList:[action.content,...state.nearbyList]}
        case 'add':
            return {...state,nearbyList:[action.content,...state.nearbyList]}
        case 'delete':
            return {...state,nearbyList:[action.content,...state.nearbyList]}
        case 'editor':
            return {...state,nearbyList:[action.content,...state.nearbyList]}
        default:
            return state;
        }
    })
const foodReducer = ((state={foodList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,foodList:[action.content,...state.foodList]}
        case 'add':
            return {...state,foodList:[action.content,...state.foodList]}
        case 'delete':
            return {...state,foodList:[action.content,...state.foodList]}
        case 'editor':
            return {...state,foodList:[action.content,...state.foodList]}
        default:
            return state;
        }
    })
const hotelReducer = ((state={hotelList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,hotelList:[action.content,...state.hotelList]}
        case 'add':
            return {...state,hotelList:[action.content,...state.hotelList]}
        case 'delete':
            return {...state,hotelList:[action.content,...state.hotelList]}
        case 'editor':
            return {...state,hotelList:[action.content,...state.hotelList]}
        default:
            return state;
        }
})
const postReducer = ((state={postList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,postList:[action.content,...state.postList]}
        case 'add':
            return {...state,postList:[action.content,...state.postList]}
        case 'delete':
            return {...state,postList:[action.content,...state.postList]}
        case 'editor':
            return {...state,postList:[action.content,...state.postList]}
        default:
            return state;
        }
})

const systemReducer = ((state={systemList:[]},action) => {
    switch(action.type){
        case 'search':
            return {...state,systemList:[action.content,...state.systemList]}
        case 'add':
            return {...state,systemList:[action.content,...state.systemList]}
        case 'delete':
            return {...state,systemList:[action.content,...state.systemList]}
        case 'editor':
            return {...state,systemList:[action.content,...state.systemList]}
        default:
            return state;
        }
})

const value = ((state={valueList:{}},action) => {
    switch(action.type){
        case 'get':
            return {valueList:action.con}//{userList:action.content}
        default:
            return state;
        }
})

const rootReducer = combineReducers({
    login:loginReducer,
    user:userReducer,
    citcul:cityCulutureReducer,
    interest:interestReducer,
    nearby:nearbyReducer,
    food:foodReducer,
    hotel:hotelReducer,
    post:postReducer,
    system:systemReducer,
    value:value
})

const store = createStore(
    rootReducer,
    applyMiddleware(thunk)
)

export default store;